import logging
from datetime import datetime
import traceback


def setup_logger(log_file):
    logging.basicConfig(filename=log_file, level=logging.INFO,
                        format='%(asctime)s - %(levelname)s - %(message)s')

def log_exception(exception):
    timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    exception_info = traceback.format_exc()  # 获取调用栈信息
    with open(r'执行结果/error_log.txt', 'a+', encoding='utf-8') as file:
        file.write(f'{timestamp} - 异常信息：{str(exception)}\n')
        file.write(f'调用栈信息：\n{exception_info}\n')  # 记录调用栈信息